<template>
  <div class="shareContainer" ref="shareContainer">
    <div class="shareheader">
      <div class="shareheader_top">
        <!-- <div style="min-width: 260px; margin: 5px 10px 18px 0px">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px"
            >保温箱名称</span
          >
          <el-input
            v-model="queryparam.name"
            placeholder="请输入保温箱编号"
            style="width: 210px; padding: 0px 8px 0px 0px"
          >
          </el-input>
        </div> -->
  
        <div style="min-width: 260px; margin: 5px 10px 18px 0px">
            <span style="font-size: 13px; padding: 0px 8px 0px 0px"
              >保温箱容量</span
            >
            <el-select
                    v-model="queryparam.capacity"
                    placeholder="请选择"
                    style="width: 172px"
                  >
                    <el-option
                      v-for="(val, k) in capacityOption"
                      :key="k"
                      :label="val"
                      :value="k"
                    >
                    </el-option>
                  </el-select>
        </div>
        <div style="min-width: 260px; margin: 5px 10px 18px 0px">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px"
            >保温箱厂商</span
          >
          <el-input
            v-model="queryparam.manufacturer"
            placeholder="保温箱厂商"
            style="width: 210px; padding: 0px 8px 0px 0px"
          >
          </el-input>
        </div>
        <div style="min-width: 260px; margin: 5px 10px 18px 0px">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px"
            >保温箱编号</span
          >
          <el-input
            v-model="queryparam.serial_number"
            placeholder="保温箱编号"
            style="width: 210px; padding: 0px 8px 0px 0px"
          >
          </el-input>
        </div>
        <div style="min-width: 100px; margin: 5px 10px 18px 0px">
          <el-button
            type="primary"
            data-tracker="P28-1"
            @click="PageIncubatorList()"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button
            type="primary"
            data-tracker="P28-2"
            @click="resetquery()"
            plain
            icon="el-icon-refresh-left"
            >重置</el-button
          >
        </div>
      </div>
    </div>
    <div class="sharecontent">
      <!-- 头部内容 -->
      <div class="sharecontent_header">
        <div class="sharecontent_header_right">
          <el-button
            v-permission="'company_incubator_create'"
            type="primary"
            plain
            data-tracker="P28-3"
            @click="handleClick()"
            style="margin: 0px 10px 10px 0px"
            >新增</el-button
          >
          <el-button
            v-permission="'company_incubator_delete'"
            type="primary"
            plain
            data-tracker="P28-4"
            @click="PageDeleteIncubator()"
            style="margin: 0px 10px 10px 0px"
            >删除</el-button
          >
          <el-button
            type="primary"
            plain
            data-tracker="P28-3"
            @click="handlePrint"
            style="margin: 0px 10px 10px 0px"
            >打印标签</el-button
          >
        </div>
        <div class="sharecontent_header_left">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
      <!-- 表单内容 -->
      <div class="sharecontent_content">
        <el-table
          ref="multipleTable"
          :max-height="maxheight"
          :data="tableData"
          border
          stripe
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" fixed width="55"> </el-table-column>
          <el-table-column
            type="index"
            fixed
            label="序号"
            width="55"
          ></el-table-column>
          <el-table-column
            fixed
            prop="manufacturer"
            label="生产厂家"
            width="150"
          >
          </el-table-column>
          <el-table-column prop="serial_number" label="编号" width="200">
          </el-table-column>
          <!-- <el-table-column prop="name" label="名称" width="200">
          </el-table-column>
          <el-table-column prop="model_number" label="型号" width="200">
          </el-table-column>
          <el-table-column prop="inner_diameter" label="内径" width="200">
          </el-table-column>
          <el-table-column prop="outer_diameter" label="外径" width="200">
          </el-table-column> -->
          <el-table-column prop="capacity" label="容量" width="200">
          </el-table-column>
          <el-table-column prop="used_status" label="使用状态" width="280">
            <template slot-scope="scope">
              {{ ["待使用", "在途中", "已损坏"][scope.row.used_status] }}
            </template>
          </el-table-column>
          <!-- <el-table-column prop="temp_layer" label="温层" width="200">
          </el-table-column> -->
          <!-- <el-table-column
            prop="empty_weight_with_ice_plate"
            label="带冰层空箱重量"
            width="200"
          >
          </el-table-column> -->

          <!-- <el-table-column prop="material" label="材质" width="200">
          </el-table-column> -->
          <!-- <el-table-column prop="shared" label="是否对外共享" width="200">
          </el-table-column>
          <el-table-column prop="ownership_type" label="来源" width="200">
          </el-table-column>
          <el-table-column prop="branch_id" label="网点" width="200">
          </el-table-column> -->

          <el-table-column prop="remark" label="备注" width="200">
          </el-table-column>
          <!-- <el-table-column prop="temp_device" label="温度计设备" width="200">
          </el-table-column>
          <el-table-column prop="shared_website" label="共享网点" width="280">
          </el-table-column> -->
 
          <el-table-column prop="status" label="是否启用" width="200">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                v-permission="'company_incubator_detail'"
                data-tracker="P28-5"
                @click="handleClick(scope.row, '1')"
                type="text"
                size="small"
                >查看</el-button
              >
              <el-button
                v-permission="'company_incubator_update'"
                data-tracker="P28-6"
                type="text"
                size="small"
                @click="handleClick(scope.row, '2')"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 弹框内容 -->
      <div>
        <el-dialog
          :title="title_name"
          :visible.sync="dialogVisible"
          width="63%"
          :close-on-click-modal="false"
        >
          <div>
            <el-form
              :inline="true"
              class="demo-form-inline"
              label-width="120px"
              :model="ruleForm"
              :rules="rules"
              ref="ruleForm"
              :disabled="orderstate === '1'"
            >
              <el-form-item label="生产厂家" prop="manufacturer">
                <el-input
                  v-model="ruleForm.manufacturer"
                  placeholder="生产厂家"
                  style="width: 172px"
                ></el-input>
              </el-form-item>
              <el-form-item label="保温箱编号" prop="serial_number">
                <el-input
                  placeholder="系统自动生成"
                  v-model="ruleForm.serial_number"
                  disabled
                ></el-input>
              </el-form-item>
              <!-- <el-form-item label="名称" prop="name">
                <el-input v-model="ruleForm.name" placeholder="名称"></el-input>
              </el-form-item> -->
              <!-- <el-form-item label="型号" prop="companyname">
                <el-input
                  v-model="ruleForm.model_number"
                  placeholder="名称"
                ></el-input>
              </el-form-item> -->
              <!-- <el-form-item label="保温箱内径">
                <el-select
                  v-model="ruleForm.inner_diameter"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in incubatorType"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="保温箱外径">
                <el-select
                  v-model="ruleForm.outer_diameter"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in incubatorOrserside"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="保温箱容量" prop="capacity">
                <el-select
                  v-model="ruleForm.capacity"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="(val,k) in capacityOption"
                    :key="k"
                    :label="val"
                    :value="k"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="温层">
                <el-select
                  v-model="ruleForm.temp_layer"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in templaOption"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="带冰板空箱重量">
                <el-select
                  v-model="ruleForm.empty_weight_with_ice_plate"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in wightOption"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="材质">
                <el-input
                  v-model="ruleForm.material"
                  placeholder="材质"
                ></el-input>
              </el-form-item> -->
              <el-form-item label="保温箱来源" prop="ownership_type">
                <el-select
                  v-model="ruleForm.ownership_type"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in ownershipoptions"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="所属网点">
                <el-select
                  v-model="ruleForm.branch_id"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in originList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>


              <!-- <el-form-item label="温度计设备">
                <el-select
                  v-model="ruleForm.temp_device"
                  multiple
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in threoptionsbox"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item> -->
              <!-- <el-form-item label="是否共享">
                <el-switch
                  v-model="ruleForm.shared"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </el-form-item>
              <el-form-item
                label="共享网点"
                v-if="ruleForm.shared == '1'"
                prop="shared_website"
              >
                <el-select
                  v-model="ruleForm.shared_website"
                  multiple
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in originList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="使用状态">
                <el-select
                  v-model="ruleForm.used_status"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in usedData"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="备注">
                <el-input
                  v-model="ruleForm.remark"
                  placeholder="备注"
                  style="width: 172px"
                ></el-input>
              </el-form-item>
              <el-form-item label="是否启用">
                <el-switch
                  style="width: 172px"
                  v-model="ruleForm.status"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="0"
                  inactive-value="1"
                >
                </el-switch>
              </el-form-item>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              :data-tracker="orderstate == '0' ? 'P28-8' : 'P28-10'"
              @click="cancledata()"
              >取 消</el-button
            >
            <!-- 代表创建的确定 -->
            <el-button
              type="primary"
              data-tracker="P28-7"
              @click="PageAddIncubator('ruleForm')"
              v-if="orderstate == '0'"
              >确 定
            </el-button>
            <!-- 修改的确定 -->
            <el-button
              type="primary"
              data-tracker="P28-9"
              @click="PageEditIncubator('ruleForm')"
              v-if="orderstate == '2'"
              >确 定
            </el-button>
          </span>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
//必须要写
import { getLodop } from "@/utils/lodop/LodopFuncs";
import {
  IncubatorList,
  EditIncubator,
  DetailIncubator,
  DeleteIncubator,
  AddIncubator,
  thermometerbox, //温度计获取
  reqIncubatorCodes,
  capacityOptions
} from "@/api/information";
import { PagewebsiteList, dictionanryList } from "../common/common";
import { reqPrintPageList, reqPrintPageDetail } from "@/api/print";
export default {
  data() {
    return {
      LODOP: {},
      title_name: "保温箱",
      ruleForm: {
        manufacturer: "", // 生产厂家
        serial_number: "", //编号
        name: "", //名称
        model_number: "", //型号
        inner_diameter: "", //内径
        outer_diameter: "", //外径
        capacity: "", //容量
        temp_layer: "", //温层
        empty_weight_with_ice_plate: "", //带冰层空箱重量
        material: "", //材质
        shared: "0", // 是否对外共享，0:不对外共享，1：共享
        ownership_type: "0", // 来源0：内部，1：租赁
        branch_id: "", //网点id
        status: "0", // 状态：0启用,1禁用
        remark: "", //备注
        temp_device: "", //温度计设备
        shared_website: [], //共享网点
        used_status: "0",
      },
      rules: {
        manufacturer: [
          { required: true, message: "生产厂家", trigger: "blur" },
        ],
        // serial_number: [{ required: true, message: "编号", trigger: "blur" }],
        // name: [{ required: true, message: "名称", trigger: "blur" }],
        ownership_type: [
          { required: true, message: "保温箱来源", trigger: "blur" },
        ],
        shared_website: [
          { required: true, message: "请填写共享网点", trigger: "blur" },
        ],
        capacity: [
          { required: true, message: "请填写保温箱容量", trigger: "blur" },
        ],
      },
      queryparam: {
        page: 0,
        page_size: 10,
        manufacturer: "", // 厂商
        serial_number: "", // 编号
        capacity:""//容量
      },
      deletparam: {
        id: [], //多选删的id
      },
      // 分页功能
      total: 0, //总条数
      currentPage4: 1,
      tableData: [], //渲染的列表数据
      dialogVisible: false, //判断弹框显示隐藏
      originList: [], //网点数据
      orderstate: "", //判断选中后的的确认按钮
      consignerID: "", //修改传递的Id
      //保温箱来源
      ownershipoptions: [],
      //   温度计
      threoptionsbox: [],
      value: "",
      //保温箱类型
      incubatorType: [],
      // 外径选择
      incubatorOrserside: [],
      // 温控要求
      templaOption: [],
      // 保温箱容量
      capacityOption: {},
      // 带冰板空箱重量
      wightOption: [],
      maxheight: 400,
      printPage: [],
      titleStr: "",
      mainlyStr: "",
      toPrintStr: "",
      usedData: [
        {
          item_code: "0",
          item_name: "待使用",
        },
        {
          item_code: "1",
          item_name: "在途中",
        },
        {
          item_code: "2",
          item_name: "已损坏",
        },
      ],
    };
  },
  components: {},
  mounted() {
    // 获取组织接口
    this.siteList();
    // 数据列表
    this.PageIncubatorList();
    // 调用数据字典
    this.Datadictionary();
    // 温度计box
    this.Pagethermometerbox();
  },
  methods: {
    // 温度计设备
    Pagethermometerbox() {
      var pame = {
        name: "",
      };
      thermometerbox(pame).then((res) => {
        var res = res.data;
        this.threoptionsbox = res;
      });
    },
    // 数据字典接口
    Datadictionary() {
      var param = [
        "ownership_ty",
        "inner_diamet",
        "outer_diamet",
        "Package_model",
        "thermosphere",
        "empty_weight",
      ];
      dictionanryList(param).then((res) => {
        var res = res.data;
        // 保温箱来源函数
        this.ownershipoptions = res.list.ownership_ty;
        // 保温箱内径
        this.incubatorType = res.list.inner_diamet;
        // 保温箱外径
        this.incubatorOrserside = res.list.outer_diamet;
        // 保温箱容量
        // this.capacityOption = res.list.Package_model;
        //  温层
        this.templaOption = res.list.thermosphere;
        // 带冰板空箱重量
        this.wightOption = res.list.empty_weight;
      });
      capacityOptions({}).then(res=>{
        console.log(res,'---')
        this.capacityOption=res.data
      })
    },
    // 关闭弹框的函数
    closepop() {
      this.dialogVisible = false;
    },
    // 获取多选删除的id号
    handleSelectionChange(val) {
      var deleid = [];
      for (var i = 0; i < val.length; i++) {
        deleid.push(val[i].id);
      }
      this.deletparam.id = deleid;
    },
    //修改
    handleClick(row, type) {
      if (row == undefined) {
        this.title_name = "创建保温箱";
        this.orderstate = "0";
        this.cancledata();
      } else if (row != "" && type == 1) {
        this.title_name = "查看保温箱";
        this.orderstate = "1";
        this.PageDetailIncubator(row.id);
      } else if (row != "" && type == 2) {
        this.title_name = "修改保温箱";
        this.orderstate = "2";
        this.consignerID = row.id;
        this.PageDetailIncubator(row.id);
      }
      this.dialogVisible = true;
    },
    // 一页有多少条
    handleSizeChange(val) {
      this.queryparam.page_size = val;
      //  数据列表接口
      this.PageIncubatorList();
    },
    // 当前第几页
    handleCurrentChange(val) {
      this.queryparam.page = val;
      //  数据列表接口
      this.PageIncubatorList();
    },
    // 点击关闭需要调用的函数
    handleClose() {
      this.closepop();
    },
    // 组织管理页面
    siteList() {
      PagewebsiteList("0").then((res) => {
        this.originList = res.data;
      });
    },
    // 保温箱列表
    PageIncubatorList() {
      IncubatorList(this.queryparam).then((res) => {
        if (res.code == 10000) {
          var res = res.data;
          this.total = res.pagination.total;
          if (res.list == null) {
            var list = [];
            this.manageData(list);
          } else {
            this.manageData(res.list);
          }
        }
      });
    },
    // 处理数据
    manageData(nameList) {
      nameList.forEach((res) => {
        // 共享网点
        var websitList = [];
        if (res.shared_website != null) {
          for (var i = 0; i < res.shared_website.length; i++) {
            websitList.push(res.shared_website[i].name);
          }
        }
        // 温度计名称
        var deviceList = [];
        if (res.temp_device != null) {
          for (var i = 0; i < res.temp_device.length; i++) {
            deviceList.push(res.temp_device[i].name);
          }
        }
        // 保温箱内径
        var diamterList = "";
        if (res.inner_diameter != null) {
          switch (res.inner_diameter) {
            case "0":
              diamterList = "160*160*160";
              break;
            case "1":
              diamterList = "254*254*260";
              break;
            case "2":
              diamterList = "355*235*284";
              break;
            case "3":
              diamterList = "550*395*284";
              break;
            case "4":
              diamterList = "674*452*408";
              break;
          }
        }
        // 保温箱外径
        var outerdiameterlist = "";
        if (res.outer_diameter != null) {
          switch (res.outer_diameter) {
            case "0":
              outerdiameterlist = "370*351*320";
              break;
            case "1":
              outerdiameterlist = "447*427*441";
              break;
            case "2":
              outerdiameterlist = "597*481*493";
              break;
            case "3":
              outerdiameterlist = "779*626*500";
              break;
            case "4":
              outerdiameterlist = "915*685*630";
              break;
          }
        }
        // 保温箱容量
        var capacityList = "";
        if (res.capacity != null) {
          capacityList=this.capacityOption[res.capacity]
          // switch (res.capacity) {
          //   case "1":
          //     capacityList = "保温箱（4L）";
          //     break;
          //   case "2":
          //     capacityList = "保温箱（16L）";
          //     break;
          //   case "3":
          //     capacityList = "保温箱（23L）";
          //     break;
          //   case "4":
          //     capacityList = "保温箱（60L）";
          //     break;
          //   case "5":
          //     capacityList = "保温箱（61L）";
          //     break;
          //   case "6":
          //     capacityList = "保温箱（102L）";
          //     break;
          //   case "7":
          //     capacityList = "保温箱（124L）";
          //     break;
          //   case "8":
          //     capacityList = "保温箱（125L）";
          //     break;
          // }
        }
        // 温层
        var templayerlist = "";
        if (res.temp_layer != null) {
          switch (res.temp_layer) {
            case "0":
              templayerlist = "常温（0- 30℃）";
              break;
            case "1":
              templayerlist = "冷藏（2~8℃）";
              break;
            case "2":
              templayerlist = "冷冻（-15~25℃）";
              break;
            case "3":
              templayerlist = "阴凉（15~25℃）";
              break;
            case "4":
              templayerlist = "干冰（-40~80℃）";
              break;
            case "5":
              templayerlist = "常温样本（0~25℃）";
              break;
            case "6":
              templayerlist = "-25℃以下";
              break;
            case "7":
              templayerlist = "临床（-60~-90℃）";
              break;
          }
        }
        //带冰板总理
        var empty_weightList = "";
        if (res.empty_weight_with_ice_plate != null) {
          switch (res.empty_weight_with_ice_plate) {
            case "0":
              empty_weightList = "10KG";
              break;
            case "1":
              empty_weightList = "17KG";
              break;
            case "2":
              empty_weightList = "22KG";
              break;
            case "3":
              empty_weightList = "34KG";
              break;
            case "4":
              empty_weightList = "50KG";
              break;
          }
        }
        res.shared = res.shared == 0 ? "不共享" : "共享";
        res.ownership_type = res.ownership_type == 0 ? "内部" : "租赁";
        res.status = res.status == 0 ? "启用" : "禁用";
        res.shared_website =
          res.shared_website != null ? websitList.toString() : ""; //共享网点
        res.temp_device = res.temp_device != null ? deviceList.toString() : ""; //温度计设备
        res.inner_diameter = res.inner_diameter != null ? diamterList : "";
        res.outer_diameter =
          res.outer_diameter != null ? outerdiameterlist : "";
        res.capacity = res.capacity != null ? capacityList : "";
        res.temp_layer = res.temp_layer != null ? templayerlist : "";
        res.empty_weight_with_ice_plate =
          res.empty_weight_with_ice_plate != null ? empty_weightList : "";
      });
      this.tableData = nameList;
    },
    // 编辑保温箱
    PageEditIncubator(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = {
            id: this.consignerID,
            manufacturer: this.ruleForm.manufacturer,
            serial_number: this.ruleForm.serial_number,
            name: this.ruleForm.name,
            model_number: this.ruleForm.model_number,
            inner_diameter: this.ruleForm.inner_diameter,
            outer_diameter: this.ruleForm.outer_diameter,
            capacity: this.ruleForm.capacity,
            temp_layer: this.ruleForm.temp_layer,
            empty_weight_with_ice_plate:
              this.ruleForm.empty_weight_with_ice_plate,
            material: this.ruleForm.material,
            shared: this.ruleForm.shared,
            ownership_type: this.ruleForm.ownership_type,
            branch_id: String(this.ruleForm.branch_id),
            status: this.ruleForm.status,
            remark: this.ruleForm.remark,
            temp_device: this.ruleForm.temp_device,
            shared_website: this.ruleForm.shared_website, //共享网点
            used_status: this.ruleForm.used_status,
          };
          EditIncubator(param).then((res) => {
            if (res.code == 10000) {
              this.$message({
                message: "修改成功",
                type: "success",
              });
              this.cancledata();
              this.PageIncubatorList();
            }
          });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    // 保温箱详情
    PageDetailIncubator(id) {
      var params = {
        id: id,
      };
      DetailIncubator(params).then((res) => {
        var res = res.data;
        var sharedList = [];
        if (res.shared_website != null) {
          res.shared_website.forEach((res) => {
            sharedList.push(res.id);
          });
        } else {
          sharedList = [];
        }

        var tempList = [];
        if (res.temp_device != null) {
          res.temp_device.forEach((res) => {
            tempList.push(res.id);
          });
        }
        this.ruleForm.manufacturer = res.manufacturer;
        this.ruleForm.serial_number = res.serial_number;
        this.ruleForm.name = res.name;
        this.ruleForm.model_number = res.model_number;
        this.ruleForm.inner_diameter = res.inner_diameter;
        this.ruleForm.outer_diameter = res.outer_diameter;
        this.ruleForm.capacity = res.capacity;
        this.ruleForm.temp_layer = res.temp_layer;
        this.ruleForm.empty_weight_with_ice_plate =
          res.empty_weight_with_ice_plate;
        this.ruleForm.material = res.material;
        this.ruleForm.shared = res.shared;
        this.ruleForm.ownership_type = res.ownership_type;
        this.ruleForm.branch_id = res.branch_id == 0 ? "" : res.branch_id;
        this.ruleForm.status = res.status;
        this.ruleForm.remark = res.remark;
        this.ruleForm.temp_device = tempList;
        this.ruleForm.shared_website = sharedList; //共享网点
        this.ruleForm.used_status = res.used_status; //共享网点
      });
    },
    // 删除保温箱
    PageDeleteIncubator() {
      var str = JSON.stringify(this.deletparam);
      DeleteIncubator(str).then((res) => {
        if (res.code == 10000) {
          this.$message({
            message: "删除成功",
            type: "success",
          });

          this.PageIncubatorList();
        }
      });
    },
    // 添加保温箱
    PageAddIncubator(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.ruleForm.temp_device =
            this.ruleForm.temp_device == [] ? [] : this.ruleForm.temp_device;
          var params = {
            manufacturer: this.ruleForm.manufacturer, // 生产厂家
            serial_number: this.ruleForm.serial_number, //编号
            name: this.ruleForm.name, //名称
            model_number: this.ruleForm.model_number, //型号
            inner_diameter: this.ruleForm.inner_diameter, //内径
            outer_diameter: this.ruleForm.outer_diameter, //外径
            capacity: this.ruleForm.capacity, //容量
            temp_layer: this.ruleForm.temp_layer, //温层
            empty_weight_with_ice_plate:
              this.ruleForm.empty_weight_with_ice_plate, //带冰层空箱重量
            material: this.ruleForm.material, //材质
            shared: String(this.ruleForm.shared), // 是否对外共享，0:不对外共享，1：共享
            ownership_type: this.ruleForm.ownership_type, // 来源0：内部，1：租赁
            branch_id: String(this.ruleForm.branch_id), //网点id
            status: this.ruleForm.status, // 状态：0启用,1禁用
            remark: this.ruleForm.remark, //备注
            temp_device: this.ruleForm.temp_device, //温度计设备
            shared_website: this.ruleForm.shared_website, //共享网点
            used_status: this.ruleForm.used_status, //使用状态
          };
          AddIncubator(params).then((res) => {
            if (res.code == 10000) {
              this.$message({
                message: "创建成功",
                type: "success",
              });
              this.cancledata();
              this.PageIncubatorList();
            }
          });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    // 点击取消
    cancledata() {
      // 清空数据
      this.closepop();
      this.clearList();
    },
    // 关闭弹框的函数
    closepop() {
      this.dialogVisible = false;
    },
    openpop() {
      this.dialogVisible = true;
    },
    // 清除数据
    clearList() {
      this.ruleForm = {
        manufacturer: "", // 生产厂家
        serial_number: "", //编号
        name: "", //名称
        model_number: "", //型号
        inner_diameter: "", //内径
        outer_diameter: "", //外径
        capacity: "", //容量
        temp_layer: "", //温层
        empty_weight_with_ice_plate: "", //带冰层空箱重量
        material: "", //材质
        shared: 0, // 是否对外共享，0:不对外共享，1：共享
        ownership_type: "0", // 来源0：内部，1：租赁
        branch_id: "", //网点id
        status: "0", // 状态：0启用,1禁用
        remark: "", //备注
        temp_device: [], //温度计设备
        shared_website: [], //共享网点
        used_status: "0", //使用状态
      };
    },
    // 重置数据
    resetquery() {
      this.queryparam.manufacturer = "";
      this.queryparam.serial_number = "";
      this.queryparam.capacity = "";
      this.PageIncubatorList();
    },
    async handlePrint() {
      //点击选中某个打印模板之后
      let module = await import("@/utils/lodop/LodopFuncs");
      module.getLodop();
      if (this.printPage.length === 0) {
        let result = await reqPrintPageList({});
        this.printPage = result.data.list.filter(
          (item) => item.template_data.template_name.indexOf("保温箱") != -1
        );
      }
      this.nextToPrint();
    },
    async printWaybills() {
      let module = await import("@/utils/lodop/LodopFuncs");
      // module.getLodop();
      //循环生成打印代码的函数,用于批量打印
      let splitStr;
      let sliceStr;
      let waybillStr = [];
      let result2 = await reqPrintPageDetail({
        id: this.printPage[0].id, //这个是模板的id
      });
      this.deletparam.id.forEach(async (idItem) => {
        let pageDetail;
        let fieldDetail;
        let result1 = await reqIncubatorCodes({ ids: [idItem] });
        fieldDetail = result1.data;
        let pushArr = [];
        //将多余的单选框选项与应该出现的值加到数组里面
        //chinese_name不要和打印模板的名称一致
        pushArr.push(
          {
            chinese_name: "保温箱编号",
            value: fieldDetail[0].serial_number,
          },
          {
            chinese_name: "保温箱容量",
            value: fieldDetail[0].capacity_name,
          }
        );
        // fieldDetail = fieldDetail.concat(pushArr);
        pageDetail = result2.data.template_data.template_design;
        this.LODOP = module.getLodop();
        pushArr.forEach((item) => {
          item.value = item.value.replace(/\s*/g, "");
          pageDetail = pageDetail.replace(item.chinese_name, item.value);
        });
        console.log(pageDetail, "pageDetail");
        //每份编号打印相同的四张
        for (let index = 0; index < 4; index++) {
          splitStr = JSON.parse(pageDetail).split(";");
          // splitStr.pop();
          this.titleStr = splitStr.slice(0, 2); //最开始init的那几行
          sliceStr = splitStr.slice(2);
          sliceStr.splice(sliceStr.length - 1, 0, "\r\nLODOP.NewPage()"); //加一行
          sliceStr.pop(); //删除最后的换行符
          waybillStr = waybillStr.concat(sliceStr);
        }
        this.mainlyStr = waybillStr;
      });
      setTimeout(() => {
        this.toPrintStr =
          this.titleStr.join(";") + this.mainlyStr.join(";").slice(0, -15);
      }, 1500);
    },
    nextToPrint() {
      let that = this;
      this.printWaybills();
      if (this.toPrintStr) {
        setTimeout(() => {
          eval(this.toPrintStr);
          LODOP.PRINT_DESIGN();
          // LODOP.PREVIEW();
        }, 2000);
      } else {
        setTimeout(() => {
          eval(this.toPrintStr);
          LODOP.PRINT_DESIGN();
          // LODOP.PREVIEW();
        }, 3000);
      }
      if (LODOP.CVERSION)
        CLODOP.On_Return = function (TaskID, Value) {
          if (that.toPrintStr) {
            that.toPrintStr = "";
            that.titleStr = "";
            that.mainlyStr = "";
          } else {
          }
        };
    },
  },
};
</script>

<style lang="less" scoped>
.shareContainer {
  padding: 10px 15px;
  background-color: #fff;
  .shareheader {
    background: white;

    .shareheader_top {
      display: flex;
      flex-wrap: wrap;
    }
  }

  // 内容
  .sharecontent {
    background: white;

    // 头部内容
    .sharecontent_header {
      .sharecontent_header_right {
        display: inline-block;
      }

      .sharecontent_header_left {
        float: right;
        padding: 0px 10px 0px 0px;
      }
    }

    // 表单内容
    .sharecontent_content {
    }
  }
}
</style>
